<template>

    <mi-list-page>
        <mi-table>
            <template #topBar>
                <mi-top-bar :data="topToolbar" />
            </template>
        </mi-table>
    </mi-list-page>


    <mi-dialog v-model="edit.show" :title="$route.meta.title">
        <site-package-edit />
    </mi-dialog>


</template>

<script setup lang="ts">
import {provide, reactive} from "vue";
import global from "@/dict/global";
import {makeModelAuth} from "@/utils/auth";
import List from "@/model/list";
import Edit from "@/model/edit";
import SitePackageEdit from "@/views/site/sitePackageEdit.vue";


const auth = makeModelAuth("site.sitePackage")
const tdWidth = global.tdWidth

const topToolbar = [
    {
        auth: auth.add,
        type: 'success',
        icon: 'Plus',
        title: '新增',
        event: (ids:number[]) => {
            edit.show = true
            list.currentRow = null
        }
    },
    {
        auth: auth.del,
        title: '删除',
        type: 'danger',
        icon: 'Delete',
        event: (ids:number[]) => {
            list.del({
                url: `/${auth.del}`,
                ids: ids,
            })
        }
    },
]

const lineToolbar = [
    {
        auth: auth.edit, title: '编辑', event: (row:any) => {
            list.currentRow = row
            edit.show = true
        }
    },
    {
        auth: auth.del, title: '删除', event: (row:any) => {
            list.del({
                url:`/${auth.del}`,
                ids: [row.id]
            })
        }
    },
]

const list = reactive(new List({
    where:{},
    url: `/${auth.index}`,
    columns:[
        {name: "id", type:'selection'},
        {name: "title", title: "套餐名称", width: tdWidth.min},
        // {name: "status", title: "状态", width: tdWidth.min, type:"switch", align: "center"},
        // {name: "create_time", title: "添加时间", width: tdWidth.min, sort:true,},
        {title: "操作", type:'toolbar',toolbar:lineToolbar},
    ],
}))

const edit = reactive(new Edit({}))

provide("list", list)
provide("edit", edit)


</script>
